﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RayDen.SceneLab.Controllers.FormControllers;

namespace RayDen.SceneLab.UI
{
    public partial class RendererForm : Form
    {
        public RendererFormController Controller;

        internal PictureBox Canvas
        {
            get { return this.ctlCanvas; }
        }

        internal ToolStripProgressBar Progress
        {
            get { return this.ctlRenderProgress; }
        }

        internal ToolStripLabel Status
        {
            get { return this.toolStripStatusLabel1; }
        }

        public RendererForm()
        {
            InitializeComponent();
            Controller = new RendererFormController(this);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (this.ctlCanvas.Image == null)
            {
                this.ctlCanvas.Image = new Bitmap(ctlCanvas.ClientRectangle.Width, ctlCanvas.ClientRectangle.Height);
            }
        }

        private async void toolStripButton1_Click(object sender, EventArgs e)
        {
            var sw = Stopwatch.StartNew();
            Status.Text = string.Format("Start rendering");
            Progress.Value = 0;
            string result = await this.Controller.Render();

            sw.Stop();
            var elapsed = sw.Elapsed;

            Status.Text = string.Format("Finished {0} Elapsed {1} ", result, elapsed);
        }
    }
}
